<template>
  <div class="MyCls">
    <!-- 默认选中：default-active="1-4-1" -->
    <el-menu :router="true" default-active="/Dashboard/Default" :unique-opened="true"
      class="el-menu-vertical-demo MyMenu " @open="handleOpen" @close="handleClose" :collapse="isCollapse"
      background-color="#222D32" text-color="white">
      <div class="Logo_Head" hidden>
        <el-row>
          <el-col :span="8">
            <img src="../../../public/Images/logo.png" width="100%" />
          </el-col>
          <el-col :span="16">
            盖茨<br />
            在线
          </el-col>
          <el-col :span="24">
            <div class="SelDiv">
              d
            </div>
          </el-col>
        </el-row>
      </div>
      <el-submenu v-if="item.children.length" :index="(idx+1).toString()" v-show="item.IsShow"
        v-for="(item,idx) in routes" :key="idx">
        <template slot="title">
          <i :class="item.meta.IconCls"></i>
          <span slot="title" v-if="item.meta">{{item.meta.title}}</span>
        </template>
        <el-menu-item-group>
          <!-- 测试数据还原点::route="item.path+'/'+child.path"  -->
          <el-menu-item :route="child.path" :index="(idx+1)+'-'+(cidx+1)" v-if="child.meta.IsSlid"
            v-for="(child,cidx) in item.children" :key="cidx">
            <i :class="child.meta.IconCls"></i>
            <!-- <router-link :to="item.path+'/'+child.path" tag="span"> -->
            {{child.meta.title}}
            <!-- </router-link> -->
          </el-menu-item>
        </el-menu-item-group>
      </el-submenu>
      <el-menu-item v-else :index="(idx+1).toString()">
        <i class="el-icon-setting"></i>
        <span slot="title" v-if="item.meta">{{item.meta.title}}</span>
      </el-menu-item>
    </el-menu>
  </div>
</template>
<style lang="scss">
.el-menu-vertical-demo:not(.el-menu--collapse) {
  width: 100%;
  min-height: 100%;
  height: 100%;
}
.MyCls {
  // .el-submenu .el-menu-item {
  //   width: 250px;
  // }
}
</style>
<style lang="scss" scoped>
.MyMenu {
  padding-top: 60px;
  height: 100%;
}
.Logo_Head {
  color: white;
  padding: 10px;
  img {
    border-radius: 50%;
    height: 50px;
  }
  //侧边导航了搜索div
  .SelDiv {
    width: 100%;
    line-height: 35px;
    background: red;
    border: 1px solid black;
    border-radius: 5px;
    &:hover {
      border-color: blue;
    }
  }
}
</style>

<script>
export default {
  data () {
    return {
      isCollapse: this.$store.state.IsCollapse,
      routes: []
    };
  },
  methods: {
    handleOpen (key, keyPath) {
      console.log(key, keyPath);
    },
    handleClose (key, keyPath) {
      console.log(key, keyPath);
    }
  },
  mounted () {
    //路由集合：this.$router.options.routes
    //let rout = this.$router.options.routes;
    //rout = rout.filter(n => n.meta != null).filter(s => s.meta.IsSlid === true)
    //this.routes=rout;
    this.$axios({
      url: '/HrApi/MenuMange/GetUserMenuList',
      method: 'GET',
      params: {
        pk_User: this.$store.state.UserInfo.pk_User
      }
    }).then(res => {
      this.routes = res.data.data
      this.$store.dispatch('SetRouterDt', res.data.data)
    })
    //this.routes = this.$store.state.RouterDt

  },
  watch: {
    '$store.state.IsCollapse' (e) {
      this.isCollapse = e
    }
  }
}
</script>